from tos import *
from threading import *
from time import sleep
from synctos import *

am = SyncAM()

class ReadThread(Thread):

    def run(self):
        while True:
            print "reading packet"
            pkt = am.read(1)
            print "got packet: ", pkt;

class WriteThread(Thread):

    def run(self):
        msg = ActiveMessage()
        msg.destination = 65535
        msg.group = 34
        msg.data = [0, 0, 0, 47]
        msg.length = 4
        while True:
            sleep(2)
            print "writing packet"
            am.write(msg, 0)

def main():

    read = ReadThread()
    read2 = ReadThread()
    write = WriteThread()

    read.start()
#    read2.start()
    write.start()


if __name__ == "__main__":
    main()
